/**  
* Filename		:	BasisAction.java  
* Description	:   
* Copyright		:   Copyright (c)2010-2011  
* Company		:   
* @author		:   yanglianbo 
* @version		:   1.0  
* Create at		:   2011-6-12 上午01:03:27  
*  
* Modification History:  
* Date			Author      	Version    	Description  
* ------------------------------------------------------------------  
* 2011-6-12     	yanglianbo    	1.0        	1.0 Version  
*/   
package com.zoomlion.example.users.web;

import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;
import org.codehaus.jackson.map.annotate.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;



import com.zoomlion.core.util.ViewPage;
import com.zoomlion.example.dao.entity.User;
import com.zoomlion.example.users.service.UserManagerService;

/**
 * @author Run
 * @基于注解驱动的Spring MVC控制器！
 */
@Controller
public class UserManagerAction {
	static Logger logger = Logger.getLogger(UserManagerAction.class.getName());
	private ViewPage page ;
	@Autowired 
	private UserManagerService userManagerService;
	@RequestMapping("/userManagerAction/queryUser.do")
	public ModelAndView queryUser(ModelMap map, User user,ViewPage page, HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView("userManager/queryUser");
//		String pageNum = request.getParameter("pageNum");
//		String numPerPage  = request.getParameter("numPerPage");
		try {
			if(page==null){
				page=new ViewPage();
				page.setStart(0);
				page.setPageNum(1);
			}
//			else
//			{
//				page.setPageNum(new Integer(request.getParameter("pageNum")).intValue());
//				page.setNumPerPage(new Integer(request.getParameter("numPerPage")).intValue());
//				
//			}
			page = userManagerService.getAllUser(user, page);
			
			mav.addObject("page", page);
		} catch (Exception e) {
			e.printStackTrace();		
		}
		return mav;
	}
	@RequestMapping("/userManagerAction/addUser.do")
	public  ModelAndView addUser(ModelMap map, User user, HttpServletRequest request, HttpServletResponse response,String currentPage) {
		ModelAndView mav = new ModelAndView("jsonView");
		try {
			userManagerService.addAllUser(user);
			
		} catch (Exception e) {
			e.printStackTrace();		
		}
		mav.addObject("user","user");
		mav.addObject("statusCode","200");
		mav.addObject("message","操作成功"); 
		mav.addObject("navTabId","queryUser");
		mav.addObject("rel","");
		mav.addObject("callbackType","closeCurrent");
		mav.addObject("forwardUrl","");
		return mav; 
	}
	@RequestMapping("/userManagerAction/openAddUser.do")
	public ModelAndView openAddUser(ModelMap map, User user, HttpServletRequest request, HttpServletResponse response,String currentPage) {
		ModelAndView mav = new ModelAndView("userManager/addUser");	
		try {
		} catch (Exception e) {
			e.printStackTrace();		
		}
		return mav;
	}
	public static Logger getLogger() {
		return logger;
	}
	public static void setLogger(Logger logger) {
		UserManagerAction.logger = logger;
	}
	public ViewPage getPage() {
		return page;
	}
	public void setPage(ViewPage page) {
		this.page = page;
	}
	public UserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(UserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
	
}
